import { firewallRequest } from '@core/utils/request';
import { PaginationResponse } from './Base';

export default class Firewall {
  static fetchList = (params: QueryParams) => {
    return firewallRequest.get<
      QueryParams,
      PaginationResponse<FirewallInstance>
    >('/ctcloud/vfw/v1_firewall_query', { params });
  };

  static fetchSummaryList = (params: QueryParams) => {
    return firewallRequest.get<
      QueryParams,
      PaginationResponse<FirewallSummary>
    >('/ctcloud/vfw/v1_firewall_simple_query', { params });
  };

  static checkNeedUpgradeResources = (params: CheckNeedUpgradeParams) => {
    return firewallRequest.post<CheckNeedUpgradeParams, boolean>(
      '/ctcloud/vfw/v1_firewall_judge_ability_upgrade',
      params,
    );
  };

  static fetchVpcList = () => {
    return firewallRequest.get<void, Array<VpcInstance>>('/ctcloud/vfw/v1_firewall_vpc_list');
  };

  static fetchSubnetList = (params: FetchSubnetListParams) => {
    return firewallRequest.get<
      FetchSubnetListParams,
      Array<SubnetInstance>
    >('/ctcloud/vfw/v1_firewall_subnet_list', { params });
  };

  static getRandomName = () => {
    return firewallRequest.get<void, string>('/ctcloud/vfw/v1_firewall_random_firewall_name');
  };
}

export interface FirewallInstance extends FirewallSummary {
  firewallState: string,
  ipProtectCount: number,
  ipUnProtectCount: number,
}

export interface FirewallSummary {
  azId: string,
  expireTime: number,
  firewallEdition: string,
  firewallId: string,
  firewallName: string,
  flowProcessingCapacity: number,
  orderTime: number,
  osId: string,
  protectionIpNum: number,
  regionId: string,
  state: boolean,
  subnetId: string,
  uid: string,
  userId: string,
  vmResourceId: string,
  vpcId: string,
  vpcIp: string,
  masterOrderId: string,
  masterResourceId: string,
}

export interface QueryParams {
  firewallName?: string,
  firewallState?: string,
  vpcIds?: string[],
  vpcIp?: string,
}

export interface CheckNeedUpgradeParams {
  flowProcessingCapacity: number,
  protectionIpNum: number,
  vpcId: string,
}

export interface ResourceDetailQueryParams {
  packageType?: number,
  id?: string,
  sellingPrice?: number,
  isPlatformSpecificResource?: string,
  billingOwner?: number,
  isPackage?: string,
  chargeOffType?: number,
  paymentPlanInitialMonth?: string,
  autoPay?: string,
  cycleCount?: string,
  cycleType?: string,
  resourceIds?: Array<string>
}

export interface RenewOrderPrice {
  totalPrice: string,
  finalPrice: string,
  itemId: string,
  resourceType: string
}

export interface VpcInstance {
  cidr: string,
  ipv6Cidrs: Array<string>,
  ipv6Enabled: boolean,
  isBuy: boolean,
  name: string,
  natGatewayIds: Array<string>,
  subnetIds: Array<string>,
  vpcId: string,
}

export interface FetchSubnetListParams {
  filterNotValid?: boolean,
  vpcId: string,
}

export interface SubnetInstance {
  availabilityZones: Array<string>,
  availableIpCount: number,
  cidr: string,
  createdAt: string,
  description: string,
  dnsList: Array<string>,
  end: string,
  gatewayIp: string,
  ipv6Cidr: string,
  ipv6End: string,
  ipv6GatewayIp: string,
  ipv6Start: string,
  name: string,
  networkAclId: string,
  ntpList: Array<string>,
  routeTableId: string,
  start: string,
  subnetId: string,
  type: number,
  updatedAt: string,
  vpcId: string
}
